//author:jxx
//此处是对表单的方法，组件，权限操作按钮等进行任意扩展(方法扩展可参照SellOrder.js)
import FormBox from "../../views/mall/FormBox.vue";
let extension = {
  components: {
    //动态扩充组件或组件路径
    //表单header、content、footer对应位置扩充的组件
    gridHeader: "", //{ template: "<div>扩展组xx件</div>" },
    gridBody: FormBox,
    gridFooter: "",
    //弹出框(修改、编辑、查看)header、content、footer对应位置扩充的组件
    modelHeader: "",
    modelBody: "",
    modelFooter: ""
  },
  buttons: { view: [], box: [], detail: [] }, //扩展的按钮
  methods: {
    //事件扩展
    onInit() {
      this.columns.push({
        title: "操作",
        fixed: "right",
        width: 160,
        render: (h, { row, column, index }) => {
          return h("div", { style: {} }, [
            h(
              "a",
              {
                props: {},
                style: { "margin-left": "10px" },
                on: {
                  click: e => {
                    console.log(row);
                    this.$router.push({
                      name: "frome_guide",
                      params: {
                        id: row.id,
                        table_configuration: row.table_configuration
                      }
                    });
                  }
                }
              },
              "表单设计"
            ),
            h(
              "a",
              {
                props: {},
                style: { "margin-left": "10px" },
                on: {
                  click: e => {
                    this.$router.push({
                      name: "frome_wt",
                      params: {
                        id: row.id,
                        table_configuration: row.table_configuration
                      }
                    });
                  }
                }
              },
              "预览"
            ),
            h(
              "el-button",
              {
                props: {
                  type: 'text',
                  disabled:(row.form_type!=3)
                },
                style: { "margin-left": "10px" },
                on: {
                  click: e => {
                    console.log("form_type", row.form_type);
                    if (row.form_type == "3") {
                      this.http
                        .post("/api/Form/GetFormActivityJson", {
                          formid: row.id
                        })
                        .then(res => {
                          // console.log("res",JSON.parse(res.data[0]))
                          //表头的名字
                          this.$refs.gridBody.box4 = true;
                          let headerName = [];
                          if(res.data.length != 0){
                            JSON.parse(res.data[0]).forEach(item => {
                              if (item.type == "p") {
                                headerName.push({
                                  field: item.id,
                                  title: item.text,
                                  type: "string",
                                  align: "center"
                                });
                              } else {
                                headerName.push({  field: item.id,
                                  title: item.name,
                                  type: "string",
                                  align: "center" });
                              }
                            });
                            console.log(headerName,"headerName")
                            this.$refs.gridBody.headerName=headerName
                            // 表头的数据内容
                            let headerNameListobj = [];
                            res.data.forEach(element => {
                              let headerNameList = [];
                              if (element != "") {
                                JSON.parse(element).map(function(e, item) {
                                  if(e.type!="p"){
                                  headerNameList[e.id] =
                                    e.value == "" ? "" : e.value;
                                  }else{
                                    headerNameList[e.id] =
                                    e.text == "" ? "" : e.text;
                                  }
                                  if (e.name == '性别') {
                                    headerNameList[e.id] = e.value == 1 ? '女' : '男'
                                  }
                                });
                                // console.log(Object.assign({},headerNameList), "headerNameListobj");
                                headerNameListobj.push(Object.assign({},headerNameList));
                              }
                            });
                            // console.log(headerNameListobj, "headerNameListobj");
                            this.$refs.gridBody.headerNameList=headerNameListobj
                          }
                          
               
                        });
              
                    }
                  }
                }
              },
              "查看"
            )
          ]);
        }
      });
    },
    updateBefore(formData) {
      //编辑保存前formData为对象，包括明细表、删除行的Id
      if (formData.mainData.form_type == undefined) {
        formData.mainData.form_type = "";
      }
      return true;
    },
    rowClick({ row, column, event }) {
      //查询界面table点击行选中当前行
      this.$refs.table.$refs.table.toggleRowSelection(row);
      return true;
    },
    addBefore(e) {
      e.detailData = [];
      return true;
    }
  }
};
export default extension;
